import request from '@/utils/request'
import type { ApiResponse, ApiListResponse } from '@/types/common'
import type { Schedule, Work } from '@/types/oa'

// 办公管理相关API接口定义
export const oaApi = {
  // 获取日程列表
  getScheduleList: (params: any): Promise<ApiListResponse<Schedule>> => {
    return request({
      url: '/api/oa/schedule',
      method: 'get',
      params,
    })
  },

  // 保存日程
  saveSchedule: (data: any): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/schedule/save',
      method: 'post',
      data,
    })
  },

  // 删除日程
  deleteSchedule: (id: number): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/schedule/delete',
      method: 'post',
      data: { id },
    })
  },

  // 获取日程详情
  getScheduleDetail: (id: number): Promise<ApiResponse<Schedule>> => {
    return request({
      url: '/api/oa/schedule/detail',
      method: 'get',
      params: { id },
    })
  },

  // 获取日程日历数据
  getScheduleCalendar: (params: any): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/schedule/calendar',
      method: 'get',
      params,
    })
  },

  // 获取工作汇报列表
  getWorkList: (params: any): Promise<ApiListResponse<Work>> => {
    return request({
      url: '/api/oa/work',
      method: 'get',
      params,
    })
  },

  // 保存工作汇报
  saveWork: (data: any): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/work/save',
      method: 'post',
      data,
    })
  },

  // 删除工作汇报
  deleteWork: (id: number): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/work/delete',
      method: 'post',
      data: { id },
    })
  },

  // 获取工作汇报详情
  getWorkDetail: (params: any): Promise<ApiResponse<Work>> => {
    return request({
      url: '/api/oa/work/detail',
      method: 'get',
      params,
    })
  },

  // 获取评论列表
  getWorkComments: (tid: number): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/work/comments',
      method: 'get',
      params: { tid },
    })
  },

  // 保存评论
  saveWorkComment: (data: any): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/work/save_comment',
      method: 'post',
      data,
    })
  },

  // 删除评论
  deleteWorkComment: (id: number): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/oa/work/delete_comment',
      method: 'post',
      data: { id },
    })
  },

  // 日程管理相关接口（从 oa/schedule.ts 合并）
  // 获取工作记录列表
  getScheduleDetailList: (params?: any) => {
    return request({
      url: '/api/oa/schedule/index',
      method: 'get',
      params,
    })
  },

  // 获取工作记录日历数据
  getScheduleCalendarDetail: (params?: any) => {
    return request({
      url: '/api/oa/schedule/calendar',
      method: 'get',
      params,
    })
  },

  // 查看工作记录详情
  viewSchedule: (params?: any) => {
    return request({
      url: '/api/oa/schedule/show',
      method: 'get',
      params,
    })
  },

  // 新增工作记录
  addSchedule: (data: any) => {
    return request({
      url: '/api/oa/schedule/store',
      method: 'post',
      data,
    })
  },

  // 编辑工作记录
  editSchedule: (data: any) => {
    return request({
      url: '/api/oa/schedule/update',
      method: 'put',
      data,
    })
  },

  // 删除工作记录
  deleteScheduleDetail: (data: any) => {
    return request({
      url: '/api/oa/schedule/destroy',
      method: 'delete',
      data,
    })
  },

  // 获取工作记录统计
  getScheduleStatistics: (params?: any) => {
    return request({
      url: '/api/oa/schedule/statistics',
      method: 'get',
      params,
    })
  },

  // 导出工作记录
  exportSchedule: (params?: any) => {
    return request({
      url: '/api/oa/schedule/export',
      method: 'get',
      params,
      responseType: 'blob',
    })
  },

  // 工作汇报相关接口（从 oa/work.ts 合并）
  // 获取工作汇报列表（发送的）
  getWorkSendList: (params?: any) => {
    return request({
      url: '/api/oa/work/send',
      method: 'get',
      params,
    })
  },

  // 获取工作汇报列表（接收的）
  getWorkReceiveList: (params?: any) => {
    return request({
      url: '/api/oa/work/receive',
      method: 'get',
      params,
    })
  },

  // 查看工作汇报详情
  viewWork: (params?: any) => {
    return request({
      url: '/api/oa/work/show',
      method: 'get',
      params,
    })
  },

  // 新增工作汇报
  addWork: (data: any) => {
    return request({
      url: '/api/oa/work/store',
      method: 'post',
      data,
    })
  },

  // 编辑工作汇报
  editWork: (data: any) => {
    return request({
      url: '/api/oa/work/update',
      method: 'put',
      data,
    })
  },

  // 删除工作汇报
  deleteWorkDetail: (data: any) => {
    return request({
      url: '/api/oa/work/destroy',
      method: 'delete',
      data,
    })
  },

  // 发送工作汇报
  sendWork: (data: any) => {
    return request({
      url: '/api/oa/work/send',
      method: 'post',
      data,
    })
  },

  // 标记工作汇报为已读
  markWorkAsRead: (data: any) => {
    return request({
      url: '/api/oa/work/read',
      method: 'post',
      data,
    })
  },

  // 回复工作汇报
  replyWork: (data: any) => {
    return request({
      url: '/api/oa/work/reply',
      method: 'post',
      data,
    })
  },

  // 获取工作汇报统计
  getWorkStatistics: (params?: any) => {
    return request({
      url: '/api/oa/work/statistics',
      method: 'get',
      params,
    })
  },
}
